import React from 'react'

import Home from '../pages/Home'
import Car from '../pages/Car'
import My from '../pages/My'
import Add from '../pages/Add'

// 二级路由
import One from '../pages/home/One'
import Two from '../pages/home/Two'

let authRoutes = [
    {
        path: "/home",
        component: Home,
        child: [
            {
                path: "/home/one",
                component: One,
                title: "home11",
                authority: ["管理员", "出题者"]
            },
            {
                path: "/home/two",
                component: Two,
                title: "home22",
                authority: ["管理员"]
            },
        ],
        authority: ["管理员", "出题者", "浏览者"]
    },
    {
        path: "/car",
        component: Car,
        authority: ["管理员", "出题者", "浏览者"]
    },
    {
        path: "/my",
        component: My,
        // auth: true,
        authority: ["管理员", "出题者"]
    },
    {
        path: "/add",
        component: Add,
        authority: ["管理员"]
    },
]

function filterRoutes(routes, auth) {
    // 递归调用
    let arr = routes.filter(item => {
        // 递归出口条件
        return item.authority.includes(auth)
    })

    arr.length > 0 && arr.forEach(item => {
        if (item.child) {
            item.child = filterRoutes(item.child, auth)
        }
    })
    return arr
}

export default function Login() {
    return (
        <div>

            <button onClick={() => {
                console.log(filterRoutes(authRoutes, "浏览者"))

            }}>登录</button>
        </div>
    )
}
